Total Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 4 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 1 | const ParserInterface = require('../ParserInterface'), |
|
49 | 2 | _.each(config, (methodConfig, method) => { |
|
50 | 2 | method = _.upperCase(method) |
|
51 | 2 | let nextMethod = { |
|
52 | path : uri, |
||
53 | method : method, |
||
54 | methodName : methodConfig.operationId ? MethodsParser._normalizeMethodName(methodConfig.operationId) : MethodsParser._getPathToMethodName(config, method, uri), |
||
55 | tags : methodConfig.tags, |
||
56 | summary : methodConfig.summary, |
||
57 | description : methodConfig.description, |
||
58 | externalDocs : methodConfig.externalDocs, |
||
59 | operationId : methodConfig.operationId, |
||
60 | produces : methodConfig.produces, |
||
61 | consumes : methodConfig.consumes, |
||
62 | schemes : methodConfig.schemes, |
||
63 | isDeprecated : methodConfig.deprecated || false, |
||
64 | security : methodConfig.security, |
||
65 | isSecure : typeof methodConfig.security !== 'undefined', |
||
66 | isGET : method === 'GET', |
||
67 | isPUT : method === 'PUT', |
||
68 | isOPTIONS : method === 'OPTIONS', |
||
69 | isDELETE : method === 'DELETE', |
||
70 | isHEAD : method === 'HEAD', |
||
71 | isPOST : method === 'POST', |
||
72 | isTRACE : method === 'TRACE', |
||
73 | isCONNECT : method === 'CONNECT', |
||
74 | isPATCH : method === 'PATCH', |
||
75 | definitions : this.definitions || {}, |
||
76 | headers : [], |
||
77 | parameters : [], |
||
78 | bodyParams : [], |
||
79 | queryParams : [], |
||
80 | formDataParams: [], |
||
81 | enums : [], |
||
82 | pathParams : [], |
||
83 | modelPath : _self.modelPath, |
||
84 | docsPath : _self.docsPath |
||
85 | } |
||
86 | |||
87 | 2 | if (_.size(methodConfig.parameters)) { |
|
88 | 1 | _self.paramParser = new ParametersParser(methodConfig.parameters, _self.parameterParserConfig) |
|
89 | 1 | nextMethod.parameters = _self.paramParser.parse() |
|
90 | 1 | nextMethod.headers = _self.paramParser.headers |
|
91 | 1 | nextMethod.enums = _self.paramParser.enums |
|
92 | 1 | nextMethod.bodyParams = _self.paramParser.bodys |
|
93 | 1 | nextMethod.queryParams = _self.paramParser.querys |
|
94 | 1 | nextMethod.formDataParams = _self.paramParser.formDatas |
|
95 | 1 | nextMethod.pathParams = _self.paramParser.paths |
|
96 | } |
||
97 | |||
98 | 2 | if (_.size(methodConfig.responses)) { |
|
99 | _self.respParser = new ResponseParser(methodConfig.responses, this.modelPath) |
||
100 | nextMethod.responses = _self.respParser.parse() |
||
101 | } |
||
102 | |||
103 | 2 | nextMethod = _self._addSecurityParameters(nextMethod) |
|
104 | 2 | nextMethod.packageName = _self.packageName |
|
105 | 2 | nextMethod.className = _self.className |
|
106 | 2 | nextMethod.moduleName = _self.moduleName |
|
107 | 2 | nextMethod.docsPath = _self.docsPath |
|
108 | 2 | nextMethod.modelPath = _self.modelPath |
|
109 | 2 | nextMethod.definitions = _self.definitions |
|
110 | |||
111 | 2 | if (nextMethod.tags) { |
|
112 | 2 | let tags = nextMethod.tags |
|
113 | 2 | for (let i = 0; i < tags.length; i++) { |
|
114 | 2 | if (typeof this.methodsGroup[tags[i]] === 'undefined') { |
|
115 | 2 | this.methodsGroup[tags[i]] = [] |
|
116 | } |
||
117 | |||
118 | 2 | this.methodsGroup[tags[i]].push(nextMethod) |
|
119 | } |
||
120 | } |
||
121 | |||
122 | 2 | _self.parseMethods.push(nextMethod) |
|
123 | |||
124 | }) |
||
125 | } |
||
228 | module.exports = MethodsParser |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.